home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap6 / 6_7 / fork_pl / fork.txt < prev    next >
Encoding:
Text File  |  1996-06-15  |  803 b   |  56 lines

  1. #!/usr/bin/perl
  2.  
  3. # Include the cgi library from chapter 1.
  4.  
  5. require "cgilib.pl";
  6.  
  7. # Initialize some variables
  8.  
  9. $data = "";
  10. %cgiDict;
  11. $theScript = "";
  12.  
  13. #Read the cgi input
  14.  
  15. &readData(*data);
  16. &parseData(*data,*cgiDict);
  17.  
  18. # Figure out which button was selected
  19.  
  20. if($cgiDict{"choice"} eq "vars")
  21. {
  22.     $theScript = "envvar.pl";
  23. }
  24. elsif($cgiDict{"choice"} eq "formdata")
  25. {
  26.     $theScript = "formdata.pl";
  27. }
  28. else
  29. {
  30.     $theScript = "fortune.sh";
  31. }
  32.  
  33. # Rest the environment
  34.  
  35. $ENV{"CONTENT_LENGTH"} = length($data);
  36. $ENV{"REQUEST_METHOD"} = "POST";
  37.  
  38. if(open(childPipe,"|-"))
  39. {
  40.     # We are the parent
  41.     #Write the CGI data to the child
  42.     print childPipe $data;
  43.     close(childPipe);
  44. }
  45. else
  46. {
  47.     #We are the child
  48.     #Try to execute the other program
  49.     exec($theScript);
  50.  
  51.     die "Exec failed.\n";
  52. }
  53.  
  54. 1;
  55.  
  56.